<template>
  <div class="nav-bar" :class="{isApp: $route.query.isApp}">
    <div class="bar" :class="{fixed: fixed, bg: isBg === '1', noneBg: isBg === '0'}">
      <span class="icon-back" v-if="isBack" @click="backPage"></span>
      <div class="nav-title">{{title}}</div>
      <div class="right-pos">
        <slot/>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: 'NavBar',
  data () {
    return {
    };
  },
  props: {
    title: [String],
    backRoute: {
      type: Function
    },
    isBg: {
      type: String,
      default: '-1'
    },
    isBack: {
      type: Boolean,
      default: true
    },
    fixed: {
      type: String,
      default: 'fixed'
    }
  },
  mounted () {
    console.log(this.$el);
  },
  methods: {
    backPage () {
      // 自定义返回键
      if (this.backRoute) {
        this.backRoute();
      } else {
        this.$router.go(-1);
      }
    }
  }
};
</script>
<style lang="less" scoped>
.right-pos {
  position: absolute;
  right: 30px;
  top: 20px;
  font-size: 28px;
  color: #666;
}
.bg {
  background: linear-gradient(37deg, rgba(38, 86, 243, 1) 0%, rgba(37, 117, 252, 1) 100%);
}
.nav-bar {
  width: 100%;
  height: 88px;
  .bar.fixed {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 999;
  }
  .bar {
    height: 88px;
    background-color: #fff;
  }

  .icon-back {
    width: 22px;
    height: 40px;
    padding: 0.2rem;
    position: absolute;
    left: 25px;
    top: 8px;
    background-image: url('/static/images/icon-arrow-back.png');
    background-position: center center;
    background-repeat: no-repeat;
    background-size: 22px 40px;
  }
  .nav-title {
    text-align: center;
    color: #252733;
    font-size: 36px;
    line-height: 88px;
    padding: 0 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-bottom: 1px solid #f9f7f7;
  }
  .bar.bg {
    background: linear-gradient(37deg, rgba(38, 86, 243, 1) 0%, rgba(37, 117, 252, 1) 100%);
    .nav-title {
      color: #fff;
      border: none;
    }
    .icon-back {
      background-image: url('/static/images/icon-arrow-back-dark.png');
    }
  }
  .bar.noneBg {
    background-color: transparent;
    .nav-title {
      color: #fff;
      border: none;
    }
    .icon-back {
      background-image: url('/static/images/icon-arrow-back-dark.png');
    }
  }
}
.isApp.nav-bar {
  height: 138px;
  .icon-back {
    top: 43px;
  }
  .bar.fixed {
    top: 0;
    padding-top: 50px;
    .icon-back {
      top: 58px;
    }
  }
  .right-pos {
    top: 70px;
  }
}
</style>
